home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d14 / cxlxplod.arc / WXOPEN.C < prev   
Text File  |  1989-06-11  |  2KB  |  81 lines

  1. /* WXOPEN.C   -    opens an exploding window */
  2.  
  3. #include <stdlib.h>
  4. #include "cxldef.h"
  5. #include "cxlvid.h"
  6. #include "cxlwin.h"
  7. #include "cxlxwin.h"
  8.  
  9. static void error_exit    (int errnum);
  10. /* error message table */
  11. static char *error_text[]= {
  12.     NULL,                               /* errnum =  0, no error        */
  13.     NULL,                               /* errnum == 1, windowing error */
  14.     "Syntax:  CXLDEMO [-switches]\n\n"
  15.         "\t -c = CGA snow reduction\n"
  16.         "\t -b = BIOS screen writing\n"
  17.         "\t -m = force monochrome text attributes",
  18.     "Memory allocation error"
  19. };
  20.  
  21.  
  22. WINDOW wxopen(int srow,int scol,int erow,int ecol,int btype,int battr,int wattr)
  23. {
  24.    struct _wxrec_t *wxrec;
  25.    register int count;
  26.    int tone = 500;
  27.    int xsrow, xscol, xerow, xecol, delta;
  28.    WINDOW xwindow;
  29.  
  30.     /* allocate memory for new record */
  31.     wxrec = malloc(sizeof(struct _wxrec_t));
  32.     if(wxrec == NULL) {
  33.        return(0);
  34.     }
  35.  
  36.     /* add new record to linked list */
  37.     if(_wxinfo.active != NULL)_wxinfo.active->next = wxrec;
  38.     wxrec->prev = _wxinfo.active;
  39.     wxrec->next = NULL;
  40.     _wxinfo.active = wxrec;
  41.     _wxinfo.total++;
  42.     _wxinfo.active->wxnum = 0;
  43.  
  44.     /* calculate number of windows to explode */
  45.     count = (erow - srow)/2;
  46.     delta = (ecol - scol)/(count * 2);
  47.  
  48.     /* explode each window */
  49.     for(--count;count > 0 ;count--) {
  50.        xsrow = srow + count;
  51.        xscol = scol + (delta * count);
  52.        xerow = erow - count;
  53.        xecol = ecol - (delta * count);
  54.        if(!wopen(xsrow,xscol,xerow,xecol,btype,battr,wattr))error_exit(1); 
  55.        sound_(tone+=100,1);
  56.        _wxinfo.active->wxnum++;
  57.     }  
  58.  
  59.     if(!(xwindow=wopen(srow,scol,erow,ecol,btype,battr,wattr)))error_exit(1); 
  60.     _wxinfo.active->wxnum++;
  61.     _wxinfo.active->wxtone = tone;
  62.     sound_(tone,1);
  63.  
  64.     /* Normal return */
  65.     return(xwindow);
  66. }
  67.  
  68. /*---------------------------------------------------------------------------*/
  69. /* this function handles abnormal termination.  If it is passed an  */
  70. /* error code of 1, then it is a windowing system error.  Otherwise */
  71. /* the error message is looked up in the error message table.       */
  72.  
  73. static void error_exit(int errnum)
  74. {
  75.     if(errnum) {
  76.         printf("\n%s\n",(errnum==1)?werrmsg():error_text[errnum]);
  77.     exit(errnum);
  78.     }
  79. }
  80.  
  81.